<?php
class RssParserRss extends RssParser
{
	/**
	 * Парсит текст
	 * Возврщает RssFeed если распарсить удалось, иначе false 
	 *
	 * @param string $text
	 * @return RssFeed 
	 */
	function Load($text)
	{
		$feed=new RssFeed( );
		if (preg_match("/^.{1,1000}?<title>(.*?)<\/title>/ius",$text,$res))
		{
			$feed->title=$res[1];
		}
		if (preg_match("/^.{1,1000}?<link>(.*?)<\/link>/ius",$text,$res))
		{
			$feed->url=$res[1];
		}
		/*if (preg_match("/^.{1,1000}?<description>(.*?)<\/description>/ius",$text,$res))
		{
			$res[1]=preg_replace("/^<!\[CDATA\[(.*?)\]\]>$/isu","\\1",$res[1]);
			$feed->description=$res[1];
		}*/
		/*if (preg_match("/^.{1,1000}?<pubDate>(.*?)<\/pubDate>/ius",$text,$res))
		{
			$feed->last_update=strtotime($res[1]);
		}*/
		
		if (preg_match_all("/<item>(.*?)<\/item>/uis",$text,$items))
		{
			foreach ((array)$items[1] as $item)
			{
				$atom=new RssAtom();
				$item=trim($item);
				if (preg_match("/<title.*?>(.*?)<\/title>/ius",$item,$res))
				{
					$res[1]=preg_replace("/^<!\[CDATA\["."(.*?)\]\]>$/isu","\\1",$res[1]);
					$atom->title=$res[1];
				}
				if (preg_match("/<link.*?>(.*?)<\/link>/",$item,$res))
				{
					$atom->url=$res[1];
				}
				if (preg_match("/<pubDate.*?>(.*?)<\/pubDate>/",$item,$res))
				{
					$atom->date=strtotime($res[1]);
				}
				if (preg_match("/<description.*?>(.*?)<\/description>/ius",$item,$res))
				{
					$res[1]=preg_replace("/^<!\[CDATA\[(.*?)\]\]>$/isu","\\1",$res[1]);
					$atom->body=$res[1];
				}
				if (preg_match("/<author.*?>(.*?)<\/author>/ius",$item,$res))
				{
					$atom->author=$res[1];
				}
				if (preg_match_all("/<category.*?>(.*?)<\/category>/ius",$item,$res_tags))
				{
					foreach ((array)$res_tags[1] as $tag)
					{
						$atom->tag_list[]=$tag;
					}
				}
				$atom->feed=&$feed;
				$feed->AddAtom( $atom );
			}
		}
		else
		{
			return false;
		}
		return $feed;
	}
}
?>